forum

Home / DeveloperSection / Forums / Checkbox isEnabled behaviour unable to figure out

Checkbox isEnabled behaviour unable to figure out

Royce Roy 2176 23-Sep-2013

Hi guys

I have three CheckBox in my WPF application and what I want is to disable/ Enable the CheckBoxes according to a Property in ViewModel.

<Grid>
    <CheckBox x:Name="cbTest1" Margin="12,341,476,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
    <CheckBox x:Name="cbTest3" Margin="74,341,414,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay }" />
    <CheckBox x:Name="cbTest2" Margin="131,341,359,5" IsEnabled="{Binding Path=BoolProperty, Mode=TwoWay }" />
    <Button x:Name="btnClick" Click="btnClick_Click" Margin="231,333,29,5" />
</Grid>
In my testing application I have written a code behind for button click
private void btnClick_Click(object sender, RoutedEventArgs e)
    {
        if (_boolProperty == true)
        {
            _boolProperty = false;
            cbTest1.IsEnabled = false;
        }
        else
        {
            _boolProperty = true;
            cbTest1.IsEnabled = true;
        }
    }

The weird behavior is that if I comment the cbTest1.IsEnabled = false; or cbTest1.IsEnabled = true; then the CheckBox es remain as disabled,

but changes in only one CheckBox say, "cbTest1"'s value to true also make changes in the other checkBoxes as well. Like if cbTest1.IsEnabled = true; then all three CheckBox are enabled. if cbTest1.IsEnabled = false; then all three CheckBox are disabled.

Anybody can enlighten me please. Why is this happening? How does binding happening here? One more question, how do I go for binding of the checkBoxes isEnabled Property with a property in viewModel?


wpf wpf 
Updated on 23-Sep-2013

Can you answer this question?


Answer

1 Answers

Liked By